define([
	'../libs/zepto',
	'../common/ajax',
	'../common/yingSoftPrg',
	'../common/yingSoftCookie',
	'../common/dialog',
	'../common/userAction',
	'../common/agentInfo'
], function() {
	this.init = function() {
		set();
		
	}

	function set() {
    function e() {
        $(".back").on('click',function() {
            a.length > 1 ? (c.pop(), a.pop(), g.pop(), window.localStorage.setItem("ARRNODE", JSON.stringify(a)), window.localStorage.setItem("ARRTITLE", JSON.stringify(c)), n(a[a.length - 1])) : (window.localStorage.removeItem("ARRNODE"), window.localStorage.removeItem("ARRTITLE"), window.location.href = "materialList?fromUrl=knowledgeChapter")
        })
    }
    function t(e) {
        var t = "/api/knowledge/getChapterMenu/" + e;
        G_AjaxApi_Record.get(t, !1,
        function(e) {
            var t = JSON.parse(e);
            if (200 === t.status) {
                var n = t.data,
                o = n.chapterMenu;
                l = o
            } else alert("数据为空")
        })
    }
    function n(e) {
        $(".chapter_Div").css('height',"100%"),
         $(".chapterUl").css('height',"100%"),
        $(".knowledgeDiv").css('display',"none"),
        menuName = c[c.length - 1];
        if(menuName.length > 12) {
				menuName = menuName.substring(0, 12) + '...';
			}
        G_Prg.$("chapterTitle").innerHTML = menuName,
        G_Prg.$("chapterUl").innerHTML = "";
        for (var t = 0; t < e.length; t++) e[t].Childs ? r(e[t], t) : o(e[t], t)
    }
    function o(e, t) {
        var n = document.createElement("li"),
        o = document.createElement("span");
        o.innerHTML = e.Name,
        o.className = "lastMenu",
        n.appendChild(o),
        n.onclick = function() {
            g.push(t),
            i(e)
        },
        G_Prg.$("chapterUl").appendChild(n)
    }
    function r(e, t) {
        var o = document.createElement("li"),
        r = document.createElement("span"),
        l = document.createElement("div");
        r.innerHTML = e.Name,
        r.className = "noLastMenu",
        o.appendChild(r),
        o.appendChild(l),
        r.onclick = function() {
            c.push(e.Name),
            a.push(e.Childs),
            g.push(t),
            window.localStorage.setItem("ARRNODE", JSON.stringify(a)),
            window.localStorage.setItem("ARRTITLE", JSON.stringify(c)),
            n(e.Childs)
        },
        l.onclick = function() {
            g.push(t),
            i(e)
        },
        G_Prg.$("chapterUl").appendChild(o)
    }
    function i(e) {
        var t = e.ID,
        n = e.Name,
        o = null;
        if (e.CPTIDS) for (var r = JSON.parse(e.CPTIDS), i = 0; i < r.length; i++) {
            var l = r[i].appID;
            G_Cookie.getAppID() == l && (o = r[i].cptID, -1 !== o.indexOf(",") && (o = o.substr(0, o.indexOf(","))))
        }
        if (G_Prg.setCookie("CPTID", o), !p || !h) for (var i = 0; i < g.length; i++) if (0 !== g[i]) return G_Prg.confirm("请充值后查看更多章节知识点！",
        function() {
            p ? window.location.href = "/recharge?fromUrl=knowledgeChapter": window.location.href = "login?fromUrl=knowledgeChapter"
        }),
        void g.pop();
        window.localStorage.setItem("ARRNODE", JSON.stringify(a)),
        window.localStorage.setItem("ARRTITLE", JSON.stringify(c)),
        window.location.href = "/knowledgeList?fromUrl=knowledgeChapter&chapterID=" + t + "&chapterName=" + n
    }
    var l = "",
    a = [],
    c = [],
    g = [],
    p = G_Cookie.getUserID(),
    h = (G_Cookie.getGuid(), G_Prg.checkVipApp()),
    s = G_Prg.getCookie("MATERIALID");
    e();
    var d = G_Prg.getQueryString("fromUrl");
    if ("knowledgeList" === d) {
        var m = window.localStorage.getItem("ARRNODE"),
        f = window.localStorage.getItem("ARRTITLE");
        a = JSON.parse(m),
        c = JSON.parse(f),
        n(a[a.length - 1])
    } else if (t(s), l) {
        var u = l.Childs;
        c.push("章节列表"),
        a.push(u),
        n(u)
    }
}
	init();
})